home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
726-750
/
743
/
foco
/
foco.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-18
|
24KB
|
1,044 lines
/*
* FoCo: Formatier-Kontroll-Programm
* (GadTools-Commodities-etc-Einführung)
*
* Autor: Michael Balzer
* balzer@heike.informatik.uni-dortmund.de
* M.BALZER@AWORLD.ZER
*
* 03/91: Erste Version (primär für MacSoft Highlights-Serie)
* Version 1.0
*
* 10/91: Änderung, Delay bevor Drivecheck durchgeführt wird
* (stand schon lange an...) und Quit-Frage bei CloseWindow
* Version 1.1
*
* 01/92: Auf Anregung von Georg Windisch doch nochmal bearbeitet...
* Bug gefunden, verursachte die überlangen Disk-Anlaufzeiten.
* Ausserdem Support für Olsens Format-Replacement (neue Flags)
* und Anpassung der Tooltype-Keywords an den "CX_"-Standard.
* Und ein bisschen Kosmetik :-)
* ACHTUNG! Keine alten Languagefiles verwenden!
* Version 1.2
*
*/
#ifndef FOCO_HDR
# include "FoCo.h"
#endif
/********************************************************************
* DEKLARATIONEN:
*/
void ArgArrayDone( void );
UBYTE **ArgArrayInit( LONG arg1, UBYTE **arg2 );
LONG ArgInt( UBYTE **arg1, UBYTE *arg2, LONG arg3 );
UBYTE *ArgString( UBYTE **arg1, UBYTE *arg2, UBYTE *arg3 );
CxObj *HotKey( UBYTE *arg1, struct MsgPort *arg2, LONG arg3 );
int GetChangeNum( int unit );
int GetBADNum( void );
void LiesProgrammTexte( char *filename );
void InitAll( int argc, char **argv );
struct Gadget *CreateAllGadgets( struct Gadget **glistptr,
void *vi, UWORD topborder );
void ShowWindow( void );
void HideWindow( void );
void ende( int, STRPTR );
void DoFormat( void );
void handleCxMsg( struct Message *msg );
void handleWinMsg( void );
void main( int argc, char *argv[] );
/********************************************************************
* GadgetIDs:
*/
#define GAD_DRIVE 1
#define GAD_NAME 2
#define GAD_FFS 3
#define GAD_NOICONS 4
#define GAD_QUICK 5
#define GAD_OK 6
#define GAD_CANCEL 7
/*
* Die folgenden haben nur bei Verwendung von Olaf (Olsen) Barthels
* Format-Replacement eine (sinnvolle :-) Funktion
*/
#define GAD_NOVERIFY 8
#define GAD_INSTALL 9
#define GAD_EJECT 10
/********************************************************************
* Globale Variablen...
*/
extern struct Library *SysBase, *DOSBase;
extern struct Library *IconBase;
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct Library *GadToolsBase = NULL;
struct Library *CxBase = NULL;
struct Screen *mysc = NULL;
struct Gadget *glist = NULL;
struct Window *mywin = NULL;
void *vi = NULL;
struct RastPort *rp;
int Xwidth, WinWidth, WinHeight;
UWORD topborder;
ULONG windowsignal = 0;
STRPTR DiskList[5] = { NULL,NULL,NULL,NULL,NULL };
STRPTR DiskName[4] = { "DF0:","DF1:","DF2:","DF3:" };
char *TextSpeicher = 0;
#define _COUNT_TXT 18
char *ProgrammText[ _COUNT_TXT ] =
{
"Formatter",
"You just inserted an unreadable disk\n"
"in drive %s.\n"
"Do you want it to be formatted?",
" Yes | NO! ",
"User-friendly disk formatter",
"Pops up on disk insertion/hotkey",
"Drive:",
"Name:",
"FFS",
"No Icons",
"Quick",
"Format!",
"Cancel!",
"Format Disk...",
"CON:0/0/512/83/Formatting Disk...",
"Quit FoCo?",
"No Verify",
"Install",
"Eject"
};
#define TXT(n) ProgrammText[n]
struct EasyStruct formatreq =
{
sizeof( struct EasyStruct ), 0,
0, 0, 0
/*TXT(0), TXT(1), TXT(2)*/
};
struct EasyStruct quitreq =
{
sizeof( struct EasyStruct ), 0,
0, 0, 0
/*TXT(0), TXT(14), TXT(2)*/
};
/********************************************************************
* Trackdisk-Variablen
*/
struct IOExtTD *ioexttd[4]={ 0,0,0,0 };
int changenum[4];
struct MsgPort *tdport=0;
/********************************************************************
* Adressen der Gadgets, Status-Variablen
*/
struct Gadget *drivegad, *namegad, *ffsgad, *noiconsgad, *quickgad,
*noverifygad, *installgad, *ejectgad;
int drive;
char name[33];
BOOL bffs=TRUE, bnoicons=TRUE, bquick=FALSE,
bnoverify=FALSE, binstall=FALSE, beject=FALSE;
/********************************************************************
* Commodities-Variablen
*/
char **ttypes = NULL, *hotstr;
struct MsgPort *cxport = 0;
ULONG cxsigflag = 0; /* signal for above */
CxObj *broker = NULL; /* Our broker */
#define POP_KEY_ID (86L) /* pop up identifier */
struct NewBroker mynb = {
NB_VERSION, /* Library needs to know version */
0 /*TXT(0)*/, /* broker internal name */
0 /*TXT(3)*/, /* commodity title */
0 /*TXT(4)*/, /* description */
NBU_NOTIFY | NBU_UNIQUE, /* We want to be the only broker */
/* with this name and we want to */
/* be notified of any attempts */
/* to add a commodity with the */
/* same name */
COF_SHOW_HIDE, /* flags */
0, /* default priority */
NULL, /* port, will fill in */
0 /* channel (reserved) */
};
/* Eine "input expression" die auf DISK_INSERTED paßt */
IX diskix = {
IX_VERSION, /* required */
IECLASS_DISKINSERTED,
0, /* Code */
~0, /* CodeMask */
0, /* qualifier I am interested in */
0,
0 /* synonyms irrelevant */
};
#define CX_DISK_ID (87L)
/********************************************************************
* Trackdisk-Support-Funktion(en)
*/
int GetChangeNum( int unit )
{
if( !ioexttd[unit] ) return( 0 );
ioexttd[unit]->iotd_Req.io_Command = TD_CHANGENUM;
DoIO( ioexttd[unit] );
return( ioexttd[unit]->iotd_Req.io_Actual );
}
int GetBADNum( void )
{
int result=-1, i, cn;
struct InfoData *infoData;
struct MsgPort *port;
if( !(infoData = AllocMem(sizeof(struct InfoData),MEMF_PUBLIC)) )
return -1;
/* ermitteln, WO eine Disk eingelegt wurde */
for( i=0; i<=3; i++ )
{
if( cn = GetChangeNum(i) )
{
if( (cn>changenum[i]) && (port=DeviceProc(DiskName[i])) )
{
/* und ob die 'BAD' oder 'NDOS' ist */
if( DoPkt( port, ACTION_DISK_INFO,
MKBADDR(infoData), 0, 0, 0, 0 ) )
{
if( infoData->id_DiskType == ID_UNREADABLE_DISK
|| infoData->id_DiskType == ID_NOT_REALLY_DOS )
result=i;
}
}
changenum[i] = cn;
}
}
FreeMem( infoData, sizeof(struct InfoData) );
return( result );
}
/********************************************************************
* INITIALISIERUNG
*/
void LiesProgrammTexte( char *filename )
{
BPTR file;
long size, i;
char *ts;
if( file = Open(filename,MODE_OLDFILE) )
{
size = Seek( file, Seek(file,0,OFFSET_END), OFFSET_BEGINNING );
if( TextSpeicher = AllocMem(size+4, NULL) )
{
*((long *)TextSpeicher) = size+4;
Read( file, TextSpeicher+4, size );
for( i=0, ts=TextSpeicher+4;
i < _COUNT_TXT;
i++, ts+=strlen(ts)+1 )
{
ProgrammText[i] = ts;
}
}
Close( file );
}
}
void InitAll( int argc, char **argv )
{
char *str;
CxObj *cxo;
int i, dr=0;
/*** Libraries öffnen... ***/
if (!(GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", 36L)))
ende(20, "Requires V36 graphics.library");
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", 36L)))
ende(20, "Requires V36 intuition.library");
if (!(GadToolsBase = OpenLibrary("gadtools.library", 36L)))
ende(20, "Requires V36 gadtools.library");
CxBase = OpenLibrary("commodities.library", 36);
if(!CxBase) ende(20,"Requires V36 commodities.library");
IconBase = OpenLibrary("icon.library", 36);
if(!IconBase) ende(20,"Requires V36 icon.library");
/*** ToolTypes (Argv) scannen ***/
ttypes = ArgArrayInit( argc, argv );
drive = ArgInt( ttypes, "DRIVE", 0 );
strcpy( name, ArgString(ttypes, "NAME", "Empty") );
if( str = ArgString(ttypes, "FLAGS", NULL) )
{
bffs = MatchToolValue( str, "FFS" );
bnoicons = MatchToolValue( str, "NOICONS" );
bquick = MatchToolValue( str, "QUICK" );
bnoverify = MatchToolValue( str, "NOVERIFY" );
binstall = MatchToolValue( str, "INSTALL" );
beject = MatchToolValue( str, "EJECT" );
}
/* Die Texte einlesen */
LiesProgrammTexte( ArgString(ttypes,"LANGUAGEFILE","FoCo.txt") );
/* und einsetzen */
formatreq.es_Title = TXT(0);
formatreq.es_TextFormat = TXT(1);
formatreq.es_GadgetFormat = TXT(2);
quitreq.es_Title = TXT(0);
quitreq.es_TextFormat = TXT(14);
quitreq.es_GadgetFormat = TXT(2);
mynb.nb_Name = TXT(0);
mynb.nb_Title = TXT(3);
mynb.nb_Descr = TXT(4);
/*** Trackdisk.device öffnen: ***/
if( !(tdport = CreateMsgPort()) )
ende(20,"Couldn't create TD MsgPort");
/* alle 4 Units antesten */
for( i=0; i<=3; i++ )
{
if( ioexttd[i] = CreateIORequest(tdport, sizeof(struct IOExtTD)) )
{
if( OpenDevice(TD_NAME, i, ioexttd[i], TDF_ALLOW_NON_3_5) )
{
DeleteIORequest( ioexttd[i] );
ioexttd[i] = 0;
}
else
{
changenum[i] = GetChangeNum(i);
/* in Liste für CycleGadget aufnehmen */
DiskList[dr++] = DiskName[i];
}
}
}
/*** Hotkey installieren: ***/
cxport = CreateMsgPort();
if( !cxport )
ende(20,"Couldn't create MsgPort");
cxsigflag = 1L << cxport->mp_SigBit; /* Signal Mask für Wait */
/* Broker erzeugen */
mynb.nb_Port = cxport;
mynb.nb_Pri = ArgInt( ttypes, "CX_PRIORITY", 0 );
if( !(broker = CxBroker(&mynb, NULL)) )
ende(0,0);
/* Hotkey installieren */
AttachCxObj( broker,
HotKey( hotstr=ArgString(ttypes,"CX_POPKEY","lcommand f"),
cxport, POP_KEY_ID) );
/* Disk-Insert-Filter installieren */
if( cxo = CxFilter(NULL) )
{
SetFilterIX( cxo, &diskix );
AttachCxObj( cxo, CxSender(cxport, CX_DISK_ID) );
AttachCxObj( broker, cxo );
}
/* Auf summierten Fehler prüfen */
if( CxObjError(broker) )
ende(20,"Internal commodities error");
/* Alles o.k., Broker aktivieren */
ActivateCxObj(broker,1L);
/* soll das Fenster gleich geöffnet werden? */
if( str=ArgString(ttypes,"CX_POPUP",NULL) )
{
if( MatchToolValue(str,"YES") )
ShowWindow();
}
}
/********************************************************************
* GADGETS
*/
struct Gadget *CreateAllGadgets(
struct Gadget **glistptr, void *vi, UWORD topborder )
{
struct NewGadget ng;
struct Gadget *gad;
long tl; /* wg. cc-Fehler */
#define TXTLNG(n) TextLength( rp, TXT(n), strlen(TXT(n)) )
/* All the gadget creation calls accept a pointer to the previous
gadget, and link the new gadget to that gadget's NextGadget field.
Also, they exit gracefully, returning NULL, if any previous gadget
was NULL. This limits the amount of checking for failure that
is needed. You only need to check before you tweak any gadget
structure or use any of its fields, and finally once at the end,
before you add the gadgets. */
/* We obligingly perform the following operation, required of
any program that uses the toolkit. It gives the toolkit a
place to stuff context data: */
gad = CreateContext(glistptr);
/* Fill out a NewGadget structure to describe the gadget we want
to create: */
ng.ng_TextAttr = mysc->Font;
ng.ng_VisualInfo = vi;
/* Längeren Label ermitteln (PropFonts!) */
tl = TXTLNG( 5 );
if( TXTLNG( 6 ) > tl )
{
tl = TXTLNG( 6 );
}
/* Drive: Cycler */
tl += mysc->WBorLeft + INTERWIDTH + 8;
/* +8 wegen Abstand Text<->Gadget */
ng.ng_LeftEdge = tl;
ng.ng_TopEdge = topborder + INTERHEIGHT;
tl = TextLength( rp, "_DFX:_", 5 );
ng.ng_Width = 40 + tl; /* (26) ist das "@" plus Seitenplatz */
ng.ng_Height = mysc->Font->ta_YSize + 4;
ng.ng_Flags = NG_HIGHLABEL;
ng.ng_GadgetText = TXT(5);
ng.ng_GadgetID = GAD_DRIVE;
drivegad = gad = CreateGadget( CYCLE_KIND, gad, &ng,
GTCY_Labels, DiskList,
GTCY_Active, drive,
TAG_DONE );
/* Name: String */
ng.ng_TopEdge += gad->Height + INTERHEIGHT;
ng.ng_Width = 22 * Xwidth;
ng.ng_Height = mysc->Font->ta_YSize + 6; /* 2 Border + 1 freie oben&unten */
ng.ng_GadgetText = TXT(6);
ng.ng_GadgetID = GAD_NAME;
namegad = gad = CreateGadget( STRING_KIND, gad, &ng,
GTST_MaxChars, 32,
GTST_String, name,
TAG_DONE );
WinWidth = gad->LeftEdge + ng.ng_Width + INTERWIDTH;
/* in ng.ng_Width sind auch die Ränder enthalten */
/*--------------------*/
/* FFS: Checkbox */
/* Checkbox-Breite: siehe gad->Width */
tl = mysc->WBorLeft + INTERWIDTH + TXTLNG( 7 ) + 8;
ng.ng_LeftEdge = tl;
ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
ng.ng_Height = mysc->Font->ta_YSize;
ng.ng_GadgetText = TXT(7);
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_GadgetID = GAD_FFS;
ffsgad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, bffs,
TAG_DONE );
/* NoVerify: Checkbox */
tl = mysc->WBorLeft + INTERWIDTH + TXTLNG( 15 ) + 8;
ng.ng_LeftEdge = tl;
ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
ng.ng_GadgetText = TXT(15);
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_GadgetID = GAD_NOVERIFY;
noverifygad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, bnoverify,
TAG_DONE );
if( ffsgad->LeftEdge < gad->LeftEdge )
ffsgad->LeftEdge = gad->LeftEdge;
else
gad->LeftEdge = ffsgad->LeftEdge;
/* NoIcons: Checkbox */
tl = TXTLNG( 8 ) + 8;
ng.ng_LeftEdge = ffsgad->LeftEdge + ffsgad->Width
+ 3*INTERWIDTH + tl;
ng.ng_TopEdge -= ng.ng_Height + INTERHEIGHT;
ng.ng_GadgetText = TXT(8);
ng.ng_GadgetID = GAD_NOICONS;
noiconsgad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, bnoicons,
TAG_DONE );
/* Install: Checkbox */
tl = TXTLNG( 16 ) + 8;
ng.ng_LeftEdge = noverifygad->LeftEdge + noverifygad->Width
+ 3*INTERWIDTH + tl;
ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
ng.ng_GadgetText = TXT(16);
ng.ng_GadgetID = GAD_INSTALL;
installgad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, binstall,
TAG_DONE );
if( noiconsgad->LeftEdge < gad->LeftEdge )
noiconsgad->LeftEdge = gad->LeftEdge;
else
gad->LeftEdge = noiconsgad->LeftEdge;
/* Quick: Checkbox */
tl = TXTLNG( 9 ) + 8;
ng.ng_LeftEdge = noiconsgad->LeftEdge + noiconsgad->Width
+ 3*INTERWIDTH + tl;
ng.ng_TopEdge -= ng.ng_Height + INTERHEIGHT;
ng.ng_GadgetText = TXT(9);
ng.ng_GadgetID = GAD_QUICK;
quickgad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, bquick,
TAG_DONE );
/* Eject: Checkbox */
tl = TXTLNG( 17 ) + 8;
ng.ng_LeftEdge = installgad->LeftEdge + installgad->Width
+ 3*INTERWIDTH + tl;
ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
ng.ng_GadgetText = TXT(17);
ng.ng_GadgetID = GAD_EJECT;
ejectgad = gad = CreateGadget( CHECKBOX_KIND, gad, &ng,
GTCB_Checked, beject,
TAG_DONE );
if( quickgad->LeftEdge < gad->LeftEdge )
quickgad->LeftEdge = gad->LeftEdge;
else
gad->LeftEdge = quickgad->LeftEdge;
tl = gad->LeftEdge + gad->Width + INTERWIDTH;
if( tl > WinWidth ) WinWidth = tl;
/*--------------------*/
/* OK: Button */
/* diese sollten etwas weiter entfernt sein */
ng.ng_LeftEdge = mysc->WBorLeft + INTERWIDTH;
ng.ng_TopEdge += gad->Height + mysc->Font->ta_YSize;
ng.ng_Height = mysc->Font->ta_YSize + 4;
tl = TXTLNG( 10 ) + 3*INTERWIDTH;
/* 1*INTERWIDTH deckt die beiden Ränder ab */
ng.ng_Width = tl;
ng.ng_GadgetText = TXT(10);
ng.ng_Flags = PLACETEXT_IN + NG_HIGHLABEL;
ng.ng_GadgetID = GAD_OK;
gad = CreateGadget( BUTTON_KIND, gad, &ng,
TAG_DONE );
/* Cancel: Button */
tl = TXTLNG( 11 ) + 3*INTERWIDTH;
ng.ng_Width = tl;
ng.ng_LeftEdge = WinWidth - INTERWIDTH - ng.ng_Width;
ng.ng_GadgetText = TXT(11);
ng.ng_Flags = 0;
ng.ng_GadgetID = GAD_CANCEL;
gad = CreateGadget( BUTTON_KIND, gad, &ng,
TAG_DONE );
WinHeight = ng.ng_TopEdge + gad->Height + INTERHEIGHT - topborder;
/* bei Buttons ist gad->Height korrekt (wg.3D) */
return(gad);
}
/********************************************************************
* FENSTER
*/
void ShowWindow( void )
{
if( mywin )
{
ScreenToFront( mywin->WScreen );
WindowToFront( mywin );
ActivateWindow( mywin );
GT_SetGadgetAttrs( drivegad, mywin, NULL,
GTCY_Active, drive,
TAG_END );
ActivateGadget( namegad, mywin, NULL );
return;
}
if( !(mysc = LockPubScreen(NULL)) )
return;
/* Da ich TextLength() benutzen will, brauche ich den RastPort */
rp = &mysc->RastPort;
topborder = mysc->WBorTop + (mysc->Font->ta_YSize + 1);
Xwidth = TextLength( rp, "XX", 2 ) / 2;
if( !(vi = GetVisualInfo(mysc, TAG_DONE)) )
{
UnlockPubScreen( NULL, mysc );
return;
}
if( !CreateAllGadgets(&glist, vi, topborder) )
{
FreeVisualInfo( vi );
UnlockPubScreen( NULL, mysc );
return;
}
/* Open the window: */
mywin = OpenWindowTags( NULL,
WA_Title, TXT(12),
WA_Left, (mysc->Width - WinWidth ) / 2,
WA_Top, (mysc->Height - WinHeight) / 2,
WA_InnerWidth, WinWidth,
WA_InnerHeight, WinHeight,
WA_AutoAdjust, TRUE,
WA_PubScreen, mysc,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_SimpleRefresh, TRUE,
WA_RMBTrap, TRUE,
WA_IDCMP, CLOSEWINDOW | REFRESHWINDOW |
CYCLEIDCMP | STRINGIDCMP | CHECKBOXIDCMP,
TAG_DONE );
if( !mywin )
{
FreeGadgets( glist );
FreeVisualInfo( vi );
UnlockPubScreen( NULL, mysc );
return;
}
ScreenToFront( mywin->WScreen );
/* AddGadgets + Intuition-Refresh + GadTools-Refresh: */
AddGList( mywin, glist, -1, -1, NULL );
RefreshGList( glist, mywin, NULL, -1 );
GT_RefreshWindow( mywin, NULL );
windowsignal = 1 << mywin->UserPort->mp_SigBit;
ActivateGadget( namegad, mywin, NULL );
}
void HideWindow( void )
{
if( mywin )
{
/* Stringgadget auslesen (für nächsten CreateGadgets oder DoFormat) */
strcpy( name, ((struct StringInfo *)namegad->SpecialInfo)->Buffer );
CloseWindow( mywin );
FreeGadgets(glist);
FreeVisualInfo(vi);
UnlockPubScreen(NULL, mysc);
mywin = 0;
windowsignal = 0;
}
}
/********************************************************************
* SHUTDOWN
*/
void ende( int code, STRPTR error )
{
struct Message *msg;
int i;
/********** Hotkey-Cleanup... ***********/
if( broker )
{
DeleteCxObjAll(broker); /* safe, even if NULL */
broker = NULL;
}
if( cxport )
{
/* now that messages are shut off, clear port */
while(msg=GetMsg(cxport)) ReplyMsg(msg);
DeleteMsgPort(cxport);
cxport = NULL;
}
ArgArrayDone();
if(IconBase) CloseLibrary(IconBase);
if(CxBase) CloseLibrary(CxBase);
/************ Window-Cleanup... *************/
if( mywin )
{
CloseWindow(mywin);
FreeGadgets(glist);
FreeVisualInfo(vi);
if(mysc) UnlockPubScreen(NULL, mysc);
}
/************ Trackdisk-Cleanup... *************/
for( i=0; i<=3; i++ )
{
if( ioexttd[i] )
{
CloseDevice( ioexttd[i] );
DeleteIORequest( ioexttd[i] );
}
}
if(tdport) DeleteMsgPort(tdport);
/************ Rest... *************/
if(TextSpeicher) FreeMem( TextSpeicher, *((long *)TextSpeicher) );
if(GadToolsBase) CloseLibrary(GadToolsBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(GfxBase) CloseLibrary(GfxBase);
if(error) Printf("Error: %s\n", error);
exit(code);
}
/********************************************************************
* FORMATIEREN
*/
void DoFormat( void )
{
char com[256];
BPTR ifh, ofh;
strcpy( com, "SYS:System/Format DRIVE " );
strcat( com, DiskList[drive] );
strcat( com, " NAME \"" );
strcat( com, name );
strcat( com, "\"" );
if( bffs ) strcat( com, " FFS" );
if( bnoicons ) strcat( com, " NOICONS" );
if( bquick ) strcat( com, " QUICK" );
if( bnoverify ) strcat( com, " NOVERIFY" );
if( binstall ) strcat( com, " INSTALL" );
if( beject ) strcat( com, " EJECT" );
ifh = Open( "NIL:", MODE_OLDFILE );
ofh = Open( TXT(13), MODE_READWRITE );
if( ofh )
{
SystemTags( com,
SYS_Input, ifh,
SYS_Output, ofh,
SYS_Asynch, TRUE,
TAG_END );
}
}
/********************************************************************
* MESSAGES VERARBEITEN
*/
void handleCxMsg( struct Message *msg )
{
ULONG msgid;
ULONG msgtype;
int d;
msgid = CxMsgID( msg );
msgtype = CxMsgType( msg );
ReplyMsg( msg );
switch( msgtype )
{
case CXM_IEVENT:
switch(msgid)
{
case POP_KEY_ID:
ShowWindow();
break;
case CX_DISK_ID:
d = GetBADNum();
if( d >= 0 )
{
if( EasyRequest( NULL, &formatreq, NULL, DiskName[d] ) )
{
for( drive=0; drive<=3 && DiskList[drive]; drive++ )
if( strcmp(DiskList[drive],DiskName[d])==0 )
break;
if( !DiskList[drive] )
drive=0;
ShowWindow();
}
}
break;
}
break;
case CXM_COMMAND:
switch(msgid)
{
case CXCMD_DISABLE:
ActivateCxObj(broker,0L);
break;
case CXCMD_ENABLE:
ActivateCxObj(broker,1L);
break;
case CXCMD_UNIQUE: /* Someone has tried to run us again */
case CXCMD_APPEAR: /* Time to pop up the window */
/* If someone tries to run us a second time the second copy
* of the program will fail and we will be sent a
* CXCMD_UNIQUE message. If we support a window then we
* Make our window appear since that is what the user wanted.
* If we do not support a window then we kill the currently
* running version 'this one' so that things like autopoint
* can be toggled on/off by running them a second time.
*/
ShowWindow();
break; /* the window */
case CXCMD_DISAPPEAR:
HideWindow();
break;
case CXCMD_KILL:
ende(0,0);
break;
}
break;
}
}
void handleWinMsg( void )
{
struct IntuiMessage *imsg;
struct Gadget *gad;
ULONG imsgClass;
UWORD imsgCode;
while( imsg = GT_GetIMsg(mywin->UserPort) )
{
imsgClass = imsg->Class;
imsgCode = imsg->Code;
/* Gadget vorrausgesetzt natürlich, macht aber nix... */
gad = (struct Gadget *)imsg->IAddress;
GT_ReplyIMsg(imsg);
switch( imsgClass )
{
case GADGETUP:
case GADGETDOWN:
switch( gad->GadgetID )
{
case GAD_DRIVE:
drive = imsgCode;
break;
case GAD_NAME:
strcpy( name, ((struct StringInfo *) gad
-> SpecialInfo) -> Buffer );
HideWindow();
DoFormat();
return;
break;
case GAD_FFS:
bffs = gad->Flags & SELECTED;
break;
case GAD_NOICONS:
bnoicons = gad->Flags & SELECTED;
break;
case GAD_QUICK:
bquick = gad->Flags & SELECTED;
break;
case GAD_NOVERIFY:
bnoverify = gad->Flags & SELECTED;
break;
case GAD_INSTALL:
binstall = gad->Flags & SELECTED;
break;
case GAD_EJECT:
beject = gad->Flags & SELECTED;
break;
case GAD_OK:
HideWindow();
DoFormat();
return;
break;
case GAD_CANCEL:
HideWindow();
return;
break;
}
ActivateGadget( namegad, mywin, NULL );
break;
case REFRESHWINDOW:
GT_BeginRefresh(mywin);
GT_EndRefresh(mywin, TRUE);
break;
case CLOSEWINDOW:
if( EasyRequest(NULL, &quitreq, NULL, NULL) )
{
ende(0,0);
}
else
{
HideWindow();
return;
}
break;
}
}
}
/********************************************************************
* MAIN
*/
void main( int argc, char *argv[] )
{
ULONG sigrcvd;
struct Message *msg;
InitAll( argc, argv );
do
{
/* auf eine Msg warten */
sigrcvd = Wait ( SIGBREAKF_CTRL_E | cxsigflag | windowsignal );
/* Commodities-Konvention: ETK ("easy to kill") */
if( sigrcvd & SIGBREAKF_CTRL_E )
ende(0,0);
/* Fenster... */
if( sigrcvd & windowsignal )
handleWinMsg();
/* Msg vom Broker... */
while(cxport && (msg=GetMsg(cxport)))
handleCxMsg(msg);
} while( 1 );
}